package com.xiaobai.netease_news.client;

import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.VideoView;

import com.xiaobai.netease_news.R;

/**
 * Created by PiscesQ on 2015/6/27.
 */
public class VideoListenerAPI {
    public static VideoListenerAPI singleInstance;
//    private VideoView videoView;

    //状态
    private boolean isPlaying = false;
    private boolean isFullScreen = false;

    public VideoListenerAPI() {
    }



    public static VideoListenerAPI getSingleInstance() {
        if (singleInstance == null) {
            singleInstance = new VideoListenerAPI();
        }
        return singleInstance;
    }

//    public void setView(VideoView videoView) {
//        this.videoView = videoView;
//
//    }

    //控制条-播放、暂停按钮监听事件的对象
    public View.OnClickListener getPlayOnClickListener(ImageView imageView, VideoView videoView) {

        View.OnClickListener ret = new OnPlayClickListener(imageView, videoView);
        return ret;
    }

    //控制条-播放暂停按钮监听类
    public class OnPlayClickListener implements View.OnClickListener {
        private ImageView imageView;
        private VideoView videoView;

        public OnPlayClickListener(ImageView imageView, VideoView videoView) {
            this.imageView = imageView;
            this.videoView = videoView;
        }
        @Override
        public void onClick(View v) {
            isPlaying = videoView.isPlaying();
            if (isPlaying) {    //正在播放
                Log.d("VideoControllerListener", "正在播放。。。。");
                videoView.pause();
                imageView.setImageResource(R.drawable.biz_video_play);
            } else {  //没有播放（停止，暂停）
                Log.d("VideoControllerListener", "暂停。。。。");
                videoView.start();
                imageView.setImageResource(R.drawable.biz_video_pause);
            }
        }
    }

    //控制条-关闭按钮监听事件的对象
    public View.OnClickListener getCloseOnClickListener(final ImageView imageView) {
//        isPlaying = videoView.isPlaying();
        View.OnClickListener ret = new View.OnClickListener() {
            @Override
            public void onClick(View v) {

            }
        };
        return ret;
    }

    //控制条-全屏按钮监听事件的对象
    public View.OnClickListener getFullScreenOnClickListener(final ImageView imageView) {
//        isPlaying = videoView.isPlaying();
        View.OnClickListener ret = new OnFullScreenClickListener(imageView);
        return ret;
    }

    //控制条-全屏事件监听类
    public class OnFullScreenClickListener implements View.OnClickListener {

        private ImageView imageView;

        public OnFullScreenClickListener(ImageView imageView) {
            this.imageView = imageView;
        }

        @Override
        public void onClick(View v) {
            if (isFullScreen) {    //全屏状态
                imageView.setImageResource(R.drawable.biz_video_expand);
                isFullScreen = false;
                //TODO 进行正常播放
            } else {  //非全屏状态
                imageView.setImageResource(R.drawable.biz_video_shrink);
                isFullScreen = true;
                //TODO 进行全屏播放
            }
        }
    }

}
